<?php
if (!defined('ROOT_PATH')) die('No direct access.');

function checkUser($fbid){
	$db = new db();
	$query = "SELECT * FROM Pengguna WHERE idFB = '$fbid'";
	$ret = $db->query($query);
	$tmp = ($ret[0]!=NULL) ? true : false;
	return $tmp;
}

function addUser($idfb,$fbname,$nama,$kontak,$email,$bio,$token,$kota,$alamat){
	$db = new db();
	$nama = amankan($nama);
	$bio = amankan($bio);
	$query = "INSERT INTO Pengguna (idFB,fb_username,nama,kontak,email,bio,`fb_access-token`,poin_reward,`poin_rating-pembeli`) VALUES ('$idfb','$fbname','$nama','$kontak','$email','$bio','$token',0,0)";
	echo $query;
	$db->exec($query);
	$id = $db->lastInsertId();
	$alamat = amankan($alamat);
	$query = "INSERT INTO Alamat (idPembeli,kota,lengkap,nama_penerima,no_kontak) VALUES ($id,'$kota','$alamat','$nama','$kontak')";
	$db->exec($query);
}
